
<%
	var p = {
		id:id!"",//required="true" description="编号"
		name:name!"",//required="true" description="隐藏域名称（ID）"
		value:value!"",//required="true" description="隐藏域值（ID）"
		labelName:labelName!"",//required="true" description="输入框名称（Name）"
		labelValue:labelValue!"",//required="true" description="输入框值（Name）"
		title:title!"",//required="true" description="选择框标题"
		url:url!"",//required="true" description="树结构数据地址"
		cssClass:cssClass!"",

		checked:(checked!"")=="true"?"true":"",
		extId:extId!"",//required="false" description="排除掉的编号（不能选择的编号）"
		isAll:isAll!"",//required="false" description="是否列出全部数据，设置true则不进行数据权限过滤（目前仅对Office有效）"
		notAllowSelectRoot:(notAllowSelectRoot!"true")=="true"?true:false,//required="false" description="不允许选择根节点"
		notAllowSelectParent:(notAllowSelectParent!"true")=="true"?true:false,//required="false" description="不允许选择父节点"
		allowClear:(allowClear!"false")=="true"?true:false,//required="false" description="是否允许清除"
		disabled:disabled!"",//required="false" description="是否限制选择，如果限制，设置为disabled"

		isSubTag:(isSubTag!"true")=="true"?true:false // 是否是嵌套在自定义标签#form里面
	};
	
%>

<div class="input-group">
	<input id="${p.id}Id" name="${p.name}" type="hidden" value="${p.value}"/>
	<input id="${p.id}Name" name="${p.labelName}" readonly="readonly" type="text" value="${p.labelValue}" class="form-control ${p.cssClass}" />
	<div class="input-group-append">
        <span class="input-group-text form-control-sm">
			<a id="${p.id}Button" href="javascript:" class=" ${p.disabled} " style="color: #1b1e21;"><i class="fa fa-search"></i></a>
        </span>
	</div>
</div>
<script type="text/javascript">
	<% if(p.isSubTag) { %>
		<![CDATA[
	<%}%>
	$("#${id}Button, #${id}Name").click(function(){
		// 是否限制选择，如果限制，设置为disabled
		if ($("#${id}Button").hasClass("disabled")){
			return true;
		}
		
		layer.open({
			  type: 2,
			  title: '选择${p.title}',
			  shadeClose: true,
			  scrollbar: false,
			  shade: 0.3,
			  area: ['280px', '80%'],
			  content: "${ctx}/tag/treeselect?url=${p.url}&checked=${p.checked}&extId=${p.extId}&isAll=${p.isAll}&selectIds=$('#${p.id}Id').val()",
			  btn: ['<i class="fa fa-plus"></i> 确定', '<i class="fa fa-times"></i> 取消'],
			  btn1: function(index, layero){

				  	var tree = layer.iframeWindow(index).tree;
					var ids = [], names = [], nodes = [];
					if ("${p.checked}" == "true"){
						nodes = tree.getCheckedNodes(true);
					}else{
						nodes = tree.getSelectedNodes();
					}
					for(var i=0; i<nodes.length; i++) {
						ids.push(nodes[i].id);
						names.push(nodes[i].name);
						break;
					}
					$("#${p.id}Id").val(ids.join(",").replace(/u_/ig,""));
					$("#${p.id}Name").val(names.join(","));

				  	layer.close(index);

			  },
			  btn2: function(index, layero){
			  }
		}); 
	});
	<% if(p.isSubTag) { %>
		]]>
	<%}%>
</script>